<template>
  <div style="background: #F4F4F4">
    <!--导航栏+轮播图-->
    <div class="a">
      <div class="a1">
        <div class="a2">
          <!--导航栏-->
          <div class="a7" v-if="user">
            <div class="a3">
              <div class="a4"><img src="../../assets/a1.png" height="30" width="110" class="aa"/></div>
              <div class="a5">
                <button class="a5a">首页</button>
                <button class="a5a">
                  <router-link :to="'MyActive'">我的活动</router-link>
                </button>
                <button class="a5a">
                  <router-link :to="'MyTribe'">我的部落</router-link>
                </button>
                <button class="a5a">
                  <router-link :to="'MyInfo'">个人信息</router-link>
                </button>
                <button class="a5a">
                  <router-link :to="'SecondClass'">第二课堂成绩单</router-link>
                </button>
                <button class="a5a">APP下载</button>
              </div>
              <div class="a6">
                <div style="width: 300px"></div>
                <div class="a6a"><img style="border-radius: 50%" height="50" width="50" :src="user.photopath" /></div>
                <div class="a6a">{{user.username}}</div>
                <div class="a6aa" @click="exitLogin">退出</div>
              </div>
            </div>
          </div>

          <!--登录-->
          <div class="login" @click="open" v-if="!user">登录</div>
          <el-dialog title="登录" :visible.sync="dialogFormVisible">
            <el-form>
              <el-row :gutter="10">
                <el-col >
                  <el-input v-model="phone" placeholder="请输入手机号"></el-input>
                </el-col>
              </el-row>
              <el-row :gutter="10" style="margin-top: 20px">
                <el-col :span="18">
                  <el-input v-model="code" placeholder="请输入验证码"></el-input>
                </el-col>
                <el-col :span="6">
                  <el-button type="primary" style="background: #66B1FF" @click="sendMsg">获取验证码</el-button>
                </el-col>
              </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button type="primary" style="background: #66B1FF;" @click="saveLogin">确定</el-button>
            </div>
          </el-dialog>


          <!--轮播图-->
          <div class="a8">
            <el-carousel indicator-position="none"  arrow="never" height="350px">
              <el-carousel-item v-for="item in 4" :key="item">
                <img onclick="alert('轮播图！')" :src="require('../../assets/b'+item+'.png')" height="350px" width="100%">
              </el-carousel-item>
            </el-carousel>
            <div class="a11">
              <div class="a9">
                <div class="a9a">
                  <router-link :to="'DreamService'">到梦服务</router-link>
                </div>
                <div class="a9a">
                  <router-link :to="'News'">校企共建</router-link>
                </div>
                <div class="a9a">
                  <router-link :to="'ActiveSearch'"></router-link>
                </div>
                <div class="a9a"></div>
              </div>
              <div class="a10"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!--公告-->
    <div class="b1">


      <el-card class="b2">
        <div class="b3">
          <div class="b5">公告</div>
          <div class="b4">Recent New</div>
        </div>
        <div class="hidden">
        <div v-for="n in newsList1" :key="n.id">
        <div class="b6" @click="toDetail(n)">
          <div>{{n.name}}</div>
          <div>[{{n.date}}]</div>
        </div>
        <div class="b7"></div>
        </div>
        </div>
        <div class="b8">
          <router-link :to="'AllNews'">查看全部>></router-link>
        </div>
      </el-card>


      <!-- 资讯-->
      <el-card class="b2">
        <div class="b3">
          <div class="b5">资讯</div>
          <div class="b4">Consult</div>
        </div>
        <div class="hidden">
        <div v-for="n in newsList2" :key="n.id">
          <div class="b6" @click="toDetail(n)">
            <div>{{n.name}}</div>
            <div>[{{n.date}}]</div>
          </div>
          <div class="b7"></div>
        </div>
        </div>
        <div class="b8">
          <router-link :to="'AllNews'">查看全部>></router-link>
          </div>
      </el-card>
    </div>
    <!--页尾-->
    <div class="c1">
      <div class="c2">
        <div class="c3">
          <div>到梦简介</div>
          <div>到梦协议</div>
          <div>到梦服务</div>
          <div>第二课堂全国活动查询</div>
          <div>第二课堂全国活动证书查询</div>
          <div>校企共建</div>
          <div>问题与帮助</div>
          <div>联系我们</div>
          <div>APP使用说明</div>
          <div>盗梦空间使用章程和制度</div>
        </div>
        <div class="c4"></div>
        <div class="c5">
          <div>京公网安备11010802024175 到梦空间系统</div>
          <div>2016-2021 Copyright©全国共青团研究中心</div>
        </div>
      </div>
    </div>


  </div>
</template>

<script>
  export default {
    name: "home",
    data(){
      return{
        dialogFormVisible:false,
        formLabelWidth:'100px',
        newsList1:[],
        newsList2:[],
        name:'',
        date:'',
        content:'',
        phone:'',
        code:'',
        user:[]
      }
    },
     methods:{
       sendMsg(){
         this.$axios.post("/front/sendMsg?phone="+this.phone).then(resp=>{
           if (resp.data.code==200){
             this.$message.success(resp.data.message)
           } else{
             this.$message.error(resp.data.message)
           }

         })

       },
        exitLogin(){
          sessionStorage.removeItem("user1")
          this.$message.success("退出登录成功")
          this.refreshPage
          location.reload()
          },
        saveLogin(){
         this.$axios.post("/front/checkMsg?phone="+this.phone+"&code="+this.code).then(resp=>{
            if (resp.data.code==200){
              this.$message.success(resp.data.message)
              sessionStorage.setItem("user1",JSON.stringify(resp.data.data))
              this.user=JSON.parse(sessionStorage.getItem("user1"))
              this.dialogFormVisible=false
              this.refreshPage
            }else{
              this.$message.error(resp.data.message)
            }
         })

       },

      open(){
        this.dialogFormVisible=true;
      },
       refreshPage() {
         // 执行完操作后调用location.reload()方法刷新页面
         location.reload();
       },
      toDetail(n){
        window.sessionStorage.setItem("news_name",n.name);
        window.sessionStorage.setItem("news_date",n.date);
        window.sessionStorage.setItem("news_content",n.content);
        this.$router.push('/front/NewsDetail')
      },
      getNewsList1(){
        this.$axios.get('/news/findBySid1').then(resp=>{
          console.log(resp.data);
          this.newsList1=resp.data
        })
      },
       getNewsList2(){
         this.$axios.get('/news/findBySid2').then(resp=>{
           this.newsList2=resp.data
         })
       },

    },
    created() {
      this.getNewsList1()
      this.getNewsList2()
      this.user=JSON.parse(sessionStorage.getItem("user1"))
    }
  }
</script>

<style scoped>
  button{
    border: none;
    background-color: transparent;
    box-shadow: none;
  }
  a{
    color: black;
    text-decoration: none;
  }
  .b8>a{
    text-decoration: none;
    color: orange;
  }
  .b8>a:hover{
    color: gold;
    cursor: pointer;
  }
  .login{
    position: absolute;
    top: 30px;
    right: 100px;
    height: 30px;
    line-height: 30px;
    padding: 0 30px;
    color: #fff;
    background: rgba(0, 0, 0, .3);
    border-radius: 15px;
    z-index: 99;
    text-align: center;
    cursor: pointer;
    font-size: 13px;
  }
  .a1{
    width: 100%;
    height: 410px;
    box-shadow: 0px 5px 10px 0 #E2E2E2;
  }
  .a2{
    position: relative;
  }
  .a7{
    width: 100%;
    height: 60px;
    position: fixed;
    z-index: 2;
    background:#FFFFFF ;

  }
  .login{
    position: absolute;
    top: 30px;
    right: 100px;
    height: 30px;
    line-height: 30px;
    padding: 0 30px;
    color: #fff;
    background: rgba(0, 0, 0, .3);
    border-radius: 15px;
    z-index: 99;
    text-align: center;
    cursor: pointer;
    font-size: 13px;
  }

  .a8{
    position: absolute;
    z-index: 1;
    width: 100%;
  }
  .a3{
    display: flex;
    width: 1210px;
    height: 50px;
    margin: auto;
  }
  .a4{
    width: 100px;
    height: 55px;
    display: grid;
    align-items: center;
    cursor: pointer;
  }
  .a5{
    flex: 1;
    font-size: 13px;
    display: flex;
    justify-content: space-evenly;
    align-items: center;
  }
  .a5a:hover{
    cursor: pointer;
    color: gold;
  }
  .a5a>a:hover{
    cursor: pointer;
    color: gold;
  }
  .a6{
    font-size: 13px;
    width: 500px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .a6a:hover{
    cursor: pointer;
  }
  .a6aa:hover{
    cursor: pointer;
    color: darkgray;
  }
  .a11{
    display: flex;
    width: 1150px;
    margin: auto;
  }
  .a9{
    height: 60px;
    width: 900px;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .a9a:hover{
    cursor: pointer;
    color: orange;
  }
  .a9a>a:hover{
    cursor: pointer;
    color: orange;
  }
  .a10{
    width: 100%;
  }
  .b1{
    margin: auto;
    margin-top: 40px;
    display: flex;
    justify-content: space-between;
    width: 1210px;
  }
  .b2{
    width: 580px;
    height: 400px;
    text-align: left;
  }
  .hidden{
    height: 282px;
    overflow-y: hidden;
  }
  .b3{
    padding-left: 20px;
  }
  .b5{
    font-weight: bold;
  }
  .b4{
    margin-top: 10px;
    font-size: 11px;
    color: gray;
  }
  .b6{
    margin-top: 5px;
    padding-left: 20px;
    padding-right: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: gray;
    height: 40px;
  }
  .b6:hover{
    cursor: pointer;
    color: black;
  }
  .b7{
    border: 1px solid #F2F2F2;
    margin: auto;
    width: 500px;
  }
  .b8{
    font-size: 13px;
    color: orange;
    text-align: right;
    padding-right: 20px;
    margin-top: 20px;
  }
  .b8:hover{
    cursor: pointer;
    color: #FDE5D4;
  }
  .c1{
    background: #D6D8DA;
    margin-top: 170px;
    width: 100%;
    height: 100px;
  }
  .c2{
    width: 1210px;
    margin: auto;
  }
  .c3{
    height: 40px;
    display: flex;
    font-size: 13px;
    justify-content: space-between;
    align-items: center;
    color: black;
    cursor: pointer;
  }
  .c4{
    border-bottom: 1px solid darkgray;
    margin-top: 10px;
  }
  .c5{
    width: 700px;
    margin: auto;
    margin-top: 20px;
    display: flex;
    font-size: 13px;
    justify-content: space-evenly;
    color: black;
  }
</style>
